package com.yuexunit.finance.project.action.v1.dto;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.yuexunit.finance.bulkstock.entity.BulkstockInfoEntity;
import com.yuexunit.finance.bulkstock.service.BulkstockInfoService;
import com.yuexunit.finance.project.action.v1.model.output.ExchangeInventoryInfo;
import com.yuexunit.fs.parse.service.FileParseService;
import com.yuexunit.inject.ComponentFactory;

/**
*@version 创建时间：2016年9月7日 上午10:32:28
*@author NTBK-021-1006
*类说明
*/

public class ExchangeInventoryCastor {
	private static List<String> EXCHANGE_TITLES = Arrays.asList(new String[] { "商品名称", "规格型号", "重量（吨）", "物流运单号", "箱号" });
	
	public static List<ExchangeInventoryInfo> fromExchangeFile(String fileUuid) {
		FileParseService fileParseService = ComponentFactory.loadClass(FileParseService.class);
		BulkstockInfoService bulkstockInfoService = ComponentFactory.loadClass(BulkstockInfoService.class);
		List<List<String>> datas = fileParseService.parseExcel(fileUuid, EXCHANGE_TITLES);
		List<ExchangeInventoryInfo> eList = new ArrayList<>();
		for (List<String> l : datas) {
			BulkstockInfoEntity bulkstockInfo = bulkstockInfoService.inquireBulkstockInfo(null, l.get(0), l.get(1));
			if (bulkstockInfo == null) {
				continue;
			}
			ExchangeInventoryInfo e = new ExchangeInventoryInfo();
			e.setBulkstockInfoId(bulkstockInfo.getBulkstockInfoId());
			e.setCaseNumber(l.get(4));
			e.setWaybillNumber(l.get(3));
			e.setWeight(new BigDecimal(l.get(2)));
			eList.add(e);
		}
		
		return eList;
	}
}
